package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.MarketCollect;
import com.cskaoyan.bean.MarketGoods;
import com.cskaoyan.bean.MarketUser;
import com.cskaoyan.bean.zhangshizhi.wx.collect.CollectBO;
import com.cskaoyan.bean.zhangshizhi.wx.collect.CollectVO;
import com.cskaoyan.service.CollectService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;



/**
 * 收藏
 *
 * @author little ants（张时智）
 * @since 2022/06/29 15:34
 */

@RestController
@RequestMapping("wx/collect")
public class CollectController {
    @Autowired
    CollectService service;

    @GetMapping("list")
    public BaseRespVo getCollect(CollectBO collectBO){

        Subject subject = SecurityUtils.getSubject();
        MarketUser principal = (MarketUser)subject.getPrincipal();
        Integer id = principal.getId();
        collectBO.setUserId(id);

        CollectVO goodsList = service.selectCollect(collectBO);

        return new BaseRespVo().ok(goodsList);

    }

    @RequestMapping("addordelete")
    public BaseRespVo addordelete (@RequestBody MarketCollect marketCollect){

        Subject subject = SecurityUtils.getSubject();
        MarketUser principal = (MarketUser)subject.getPrincipal();
        Integer id = principal.getId();

        marketCollect.setUserId(id);

        // marketCollect.setUserId(1);

        service.addGoodsToCollect(marketCollect);

        return new BaseRespVo().ok();

    }





}
